package com.cbt.cbtBlog.config;

import java.util.concurrent.Executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {
   private int corePoolSize = 10;
   private int maxPoolSize = 100;
   private int queueCapacity = 10;
   private int keepAliveSeconds = 3000;

   @Bean
   public Executor taskExector() {
      ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
      executor.setCorePoolSize(this.corePoolSize);
      executor.setMaxPoolSize(this.maxPoolSize);
      executor.setQueueCapacity(this.queueCapacity);
      executor.setKeepAliveSeconds(this.keepAliveSeconds);
      executor.initialize();
      return executor;
   }
}
